package com.quxiu.common.core.utils;

import java.util.regex.Pattern;

/**
 * 正则校验工具类
 */
public class RegexUtils {
    // 由字母、数字和下划线组成，且不能以数字开头
    public static final String REGEX_ALPHANUMERIC_UNDERLINE_NO_UNDERSCORE = "^(?![0-9]+$)(?![a-zA-Z]+$)[A-Za-z][A-Za-z_0-9]{0,}$";
    public static final Pattern PATTERN_ALPHANUMERIC_UNDERLINE_NO_UNDERSCORE = Pattern.compile(REGEX_ALPHANUMERIC_UNDERLINE_NO_UNDERSCORE);
    // 由中文、字母、数字组成
    public static final String REGEX_CHINESE_ALPHANUMERIC = "^[\\u4e00-\\u9fa5A-Za-z0-9]+$";
    public static final Pattern PATTERN_CHINESE_ALPHANUMERIC = Pattern.compile(REGEX_CHINESE_ALPHANUMERIC);

    // 不能是数据库关键字
    public static final String REGEX_NOT_DB_KEYWORD = "^(?!(SELECT|FROM|WHERE|CREATE|TABLE|INDEX|INSERT|UPDATE|DELETE|DROP|ALTER|JOIN|UNION|GROUP BY|ORDER BY|HAVING|AND|OR|NOT))\\w+$";
    public static final Pattern PATTERN_NOT_DB_KEYWORD = Pattern.compile(REGEX_NOT_DB_KEYWORD);


    /**
     * 验证是否匹配正则
     * @param pattern
     * @param str
     * @return
     */
    public static boolean matches(Pattern pattern, String str) {
        return pattern.matcher(str).matches();
    }
}
